package com.jixiang.goods.config;

import cn.hutool.core.util.StrUtil;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

//    @Value("${spring.redis.host}")
//    String redisLocal;
//
//    @Value("${spring.redis.port}")
//    String redisPort;
//
//    @Value("${spring.redis.password}")
//    String redisPassword;
    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private Integer port;

    @Value("${spring.redis.password}")
    private String password;


//    @Bean
//    public RedissonClient redissonClient(){
//        Config config=new Config();
//        config.useSingleServer().setAddress("redis://192.168.3.35:6379").setPassword("jixiang");
////        config.useSingleServer().setAddress("redis://"+redisLocal+":"+redisPort).setPassword(redisPassword);
//        return Redisson.create(config);
//    }
    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + host + ":" + port);
        if (StrUtil.isNotBlank(password)) {
            config.useSingleServer().setPassword(password);
        }
        return Redisson.create(config);
    }



}
